package logic.SysOrganizationalRole

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysOrganizationalRole
import cn.ibizlab.core.ad.service.SysOrganizationalRoleService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  授权给角色
 */
class RoleAuth {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    //item
    def _item = new SysRoleMember()
    def _srfactionparam = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //连接名称
        if(((RuleUtils.test(_default.get('srfactionparam'), 'ISNOTNULL', 'null')))) {
            prepareparam1()
        }
    }

    //准备参数srfactionparam
    def prepareparam1() {
        _srfactionparam.set("", _default.get("srfactionparam"))

        if(true) {
            loopsubcall1()
        }
    }

    //结束
    def end1() {

    }

    //循环子调用
    def loopsubcall1() {
    //未支持的处理节点

        //连接名称
        if(true) {
            prepareparam2()
        }
        //连接名称
        else if(true) {
            end1()
        }
    }

    //准备参数
    def prepareparam2() {
        _item.set("id", _item.get("srfkey"))
        _item.set("member_type", "organizationalRole")
        _item.set("member_uid", _default.get("id"))
        _item.set("member_name", _default.get("name"))

        if(true) {
            deaction1()
        }
    }

    //实体行为
    def deaction1() {
        SpringContextHolder.getBean(SysRoleMemberService.class).save(_item)

    }

}
